#ifndef DATAFLOW_H
#define DATAFLOW_H


#include <string>

using std::string;

class DataFlow
{
public:
    DataFlow(): BufferLength(0), Buffer(NULL) { }
    DataFlow(const string s)
    {
        SetData(s.data(), s.length() + 1);
    }
    DataFlow(const char* s)
    {
        SetData(s, s ? strlen(s) + 1 : 0);
    }
    DataFlow(const long int n)
    {
        SetData((char *)&n, sizeof(long int));
    }
    DataFlow(const DataFlow &orig)
    {
        SetData(orig.Buffer, orig.BufferLength);
    }
    DataFlow(const char* buffer, unsigned int length)
    {
        SetData(buffer, length);
    }

    DataFlow & operator = ( const DataFlow &rhs )
    {
		ClearBuffer();
		SetData(rhs.Buffer, rhs.BufferLength);
        return *this;
    }
    ~DataFlow()
    {
        ClearBuffer();
    }
    void ClearBuffer()
    {
        if ((BufferLength > 0 ) && (Buffer))
        {
            BufferLength = 0;
            delete [] Buffer;
            Buffer = NULL;
        }

    }
    void SetData(const char* buffer, unsigned int length)
    {
        if ((buffer) && (length > 0))
        {
            BufferLength = length;
            Buffer = new char[BufferLength];
            memcpy(Buffer, buffer, length);
        }
        else
        {
            BufferLength = 0;
            Buffer = NULL;
        }
    }
    char * GetData() const
    {
        return Buffer;
    }
    unsigned int GetLength() const
    {
        return BufferLength;
    }

protected:
    //bool changed;
    unsigned int BufferLength;
    char *Buffer;
};

















#endif